<template>
  <div id="msg-dependencies" v-if="msgCount == 0">
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "MyMsg",
  data() {
    return {};
  },
  computed: {
    ...mapState({
      // 映射 this.type 为 store.state.msg.type
      type: state => state.msg.type,
      message: state => state.msg.message,
      duration: state => state.msg.duration,
      needRedirect: state => state.msg.needRedirect,
      redirectPathName: state => state.msg.redirectPathName,
      needGoBack: state => state.msg.needGoBack
    }),
    msgCount() {
      if (this.message !== "") {
        var param = {
          type: this.type,
          message: this.message,
          duration: this.duration,
          showClose: true
        };
        if (this.needRedirect && this.redirectPathName.length > 0) {
          param.onClose = () => this.$router.replace({ name: this.redirectPathName });
        }
        if (this.needGoBack) {
          param.onClose = () => this.$router.go(-1);
        }
        console.log("message param:", param);
        this.$message(param);
      }
      return this.$store.state.msg.count;
    }
  }
};
</script>
